<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        // 数组的解构赋值
        let [a,b,c] = [1,2,3]

        // 默认值 解构赋值允许指定默认值
            // 当数组成员等于 undefined 默认值会生效
        let [foo = true] = []
        let [x, y = 'a'] = ['b', 'c'] //x = 'b' y = 'c'
        let [x, y = 'a'] = ['b', undefined] // x = 'b' y = 'a'


        // 对象的解构赋值
            // 变量名与属性名相同 才能取到正确的值
        let {foo, bar} = { foo: 'aaa', bar: 'bbb' }
        foo // 'aaa'
        bar // 'bbb'

        // 变量没有对应的同名属性 
        let {baz} = { foo: 'aaa', bar: 'bbb' }
        baz //undefined
        
        // 当变量名与属性名不一致时 必须写成下面这样
        let { foo: baz } = { first: 'hello', last: 'world' };
        let { first: f, last: l } = obj;
        f // 'hello'
        l // 'world'


    </script>
</body>
</html>